<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 等待第一个成功的状态，如果都失败了, 返回一个失败状态的promise的对象，值是所有的都失败
        const sleep = s => new Promise((resolve,reject) => setTimeout(() => { reject('error') }, s * 1000))

        const promises = [
            Promise.reject('error'),
            // sleep(5),
            Promise.reject('666'),
            // sleep(3)
            // Promise.reject('333')
            sleep(3)
        ]

        const res = Promise.any(promises)
        console.log(res)
        res.then(res => {
            console.log(res)
        }).catch(err => {
            console.log(err)
        })
        // Promise.any(promises).then(res => {
        //     // 等结果--> 有了结果，才执行.then的回调
        //     console.log(res)
        // })
    </script>
</body>
</html>